package com.atguigu.servlet;

import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebInitParam;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.Enumeration;

@WebServlet(value = "/bconfig",initParams = {
        @WebInitParam(name = "user",value = "ls"),
        @WebInitParam(name="pwd",value = "123321")
})
public class ServletBConfig extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("ServletBConfig 请求到达了");

        ServletConfig servletConfig = this.getServletConfig();

        Enumeration<String> parameterNames = servletConfig.getInitParameterNames();
        while (parameterNames.hasMoreElements()){
            String name = parameterNames.nextElement();
            String value = servletConfig.getInitParameter(name);
            System.out.println(name+" == "+value);
        }


        resp.getWriter().println("ServletBConfig Response Success");

    }
}
